﻿Imports BUS
Imports DTO

Public Class frmxlcapnhatnhanvien

    Private _maNhanVien As Integer
    Public Property MaNhanVien() As Integer
        Get
            Return _maNhanVien
        End Get
        Set(ByVal value As Integer)
            _maNhanVien = value
        End Set
    End Property
    Private Sub frmxlcapnhatnhanvien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dsbc As New List(Of BangCapDTO)()
        Dim busbc As New BangCapBUS()
        dsbc = busbc.LayDSBangCap()
        LookUpbangcap.Properties.DataSource = dsbc
        LookUpbangcap.Properties.DisplayMember = "TenBangCap"
        LookUpbangcap.Properties.ValueMember = "MaBangCap"
        Dim dsbp As New List(Of BoPhanDTO)()
        Dim busbp As New BoPhanBUS()
        dsbp = busbp.LayDSBoPhan()
        LookUpbophan.Properties.DataSource = dsbp
        LookUpbophan.Properties.DisplayMember = "TenBoPhan"
        LookUpbophan.Properties.ValueMember = "MaBoPhan"
        Dim dscv As New List(Of ChucVuDTO)()
        Dim buscv As New ChucVuBUS()
        dscv = buscv.LayDSChucVu()
        LookUpchucvu.Properties.DataSource = dscv
        LookUpchucvu.Properties.DisplayMember = "TenChucVu"
        LookUpchucvu.Properties.ValueMember = "MaChucVu"
        LookUpbangcap.EditValue = 4
        LookUpbophan.EditValue = 1
        LookUpchucvu.EditValue = 5
    End Sub

    Private Sub btnchapnhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnchapnhan.Click
        Try
            Dim sql As String = "Update NHANVIEN Set HoTen=" + "'" + txthoten.Text + "'" + "," + "NgaySinh=" + "'" + DateEditngaysinh.DateTime + "'" + ","
            sql = sql + "DiaChi=" + "'" + txtdiachi.Text + "'" + "," + "DienThoai=" + "'" + mtxtdienthoai.Text + "'" + "," + "MaBangCap=" + LookUpbangcap.EditValue.ToString() + ","
            sql = sql + "MaBoPhan=" + LookUpbophan.EditValue.ToString() + "," + "MaChucVu=" + LookUpchucvu.EditValue.ToString() + " Where MaNhanVien=" + _maNhanVien.ToString()
            Dim bus As New NhanVienBUS()
            Dim kq As Integer = bus.CapNhatNhanVien(sql)
            If kq = 1 Then
                MessageBox.Show("Câp nhật thành công !")
                Me.Close()
            Else
                MessageBox.Show("Câp nhật thất bại !")
            End If
        Catch ex As Exception
            MessageBox.Show("Lỗi ! " & ex.Message)
        End Try
    End Sub

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub
End Class